package kiyut.ekspos;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Container;
import java.awt.Desktop;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.GridLayout;
import java.awt.Insets;
import java.awt.Rectangle;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.InputEvent;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.WindowEvent;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.ByteBuffer;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.ResourceBundle;
import java.util.logging.Level;

import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.CellEditor;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JComponent;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenuBar;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import javax.swing.JScrollPane;
import javax.swing.JTabbedPane;
import javax.swing.JTextField;
import javax.swing.JToolBar;
import javax.swing.SwingConstants;
import javax.swing.SwingUtilities;
import javax.swing.border.EmptyBorder;
import javax.swing.border.LineBorder;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ListDataEvent;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.TreeSelectionEvent;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.TreeCellEditor;
import javax.swing.tree.TreePath;
import javax.swing.tree.TreeSelectionModel;

import kiyut.ekspos.prefs.BrowseWindowPreferences;
import kiyut.ekspos.prefs.GeneralPreferences;
import kiyut.ekspos.prefs.IIOPreferences;
import kiyut.swing.shell.event.ShellAdapter;
import kiyut.swing.shell.event.ShellEvent;
import kiyut.swing.shell.util.CmisProgressMonitor;
import kiyut.swing.statusbar.MyProgressBar;
import kiyut.swing.statusbar.StatusBar;
import kiyut.swing.statusbar.StatusBarItem;
import kiyut.swing.util.MenuFactory;

import org.apache.chemistry.opencmis.client.api.CmisObject;
import org.apache.chemistry.opencmis.client.api.Document;
import org.apache.chemistry.opencmis.client.api.Folder;
import org.apache.chemistry.opencmis.client.api.Property;
import org.apache.chemistry.opencmis.client.runtime.FolderImpl;
import org.apache.chemistry.opencmis.commons.PropertyIds;
import org.apache.chemistry.opencmis.commons.enums.BaseTypeId;
import org.apache.chemistry.opencmis.commons.enums.VersioningState;
import org.apache.chemistry.opencmis.commons.exceptions.CmisBaseException;
import org.apache.chemistry.opencmis.commons.exceptions.CmisContentAlreadyExistsException;
import org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException;
import org.apache.chemistry.opencmis.commons.exceptions.CmisPermissionDeniedException;
import org.flexdock.docking.DockableFactory;
import org.flexdock.docking.DockingConstants;
import org.flexdock.docking.DockingManager;
import org.flexdock.docking.state.PersistenceException;
import org.flexdock.perspective.LayoutSequence;
import org.flexdock.perspective.Perspective;
import org.flexdock.perspective.PerspectiveFactory;
import org.flexdock.perspective.PerspectiveManager;
import org.flexdock.view.View;
import org.flexdock.view.Viewport;
import org.jdesktop.swingx.JXErrorPane;
import org.jdesktop.swingx.error.ErrorInfo;

import fr.umlv.authentication.SessionHandler;
import fr.umlv.cmis.gedconfig.Shortcut;
import fr.umlv.cmis.gedconfig.XMLAccess;
import fr.umlv.cmis.gedconfig.XMLNameAlreadyExistException;
import fr.umlv.cmis.listview.CmisObjectListView;
import fr.umlv.cmis.listview.CmisObjectListViewModel;
import fr.umlv.cmis.listview.CmisThumbnailView;
import fr.umlv.cmis.listview.ViewComponent;
import fr.umlv.cmis.treeview.CmiSObjectTreeModel;
import fr.umlv.cmis.treeview.CmisObjectTreeNode;
import fr.umlv.cmis.treeview.CmisObjectTreeView;
import fr.umlv.dnd.CmisObjectTransferHandler;
import fr.umlv.favorites.BookmarkView;
import fr.umlv.history.HistoryView;
import fr.umlv.information.PanelInformation;
import fr.umlv.metadata.MetadataWizard;
import fr.umlv.model.ClientModel;
import fr.umlv.search.CmisNoResultsException;
import fr.umlv.search.MalformedCritersException;
import fr.umlv.search.SearchModel;
import fr.umlv.search.SearchWindow;
import fr.umlv.users.InviteUsersView;
import fr.umlv.utils.ExceptionUtils;
import fr.umlv.utils.InfiniteProgressPanel;

// TODO: Auto-generated Javadoc
/**
 * The Class BrowserWindow.
 */
public class BrowserWindow extends JFrame {

	/** The Constant serialVersionUID. */
	private static final long serialVersionUID = 1L;

	/** The Constant EXIT_ACTION_COMMAND. */
	public static final String EXIT_ACTION_COMMAND = "Exit";

	/** The Constant CUT_ACTION_COMMAND. */
	public static final String CUT_ACTION_COMMAND = "Cut";

	/** The Constant COPY_ACTION_COMMAND. */
	public static final String COPY_ACTION_COMMAND = "Copy";

	/** The Constant PASTE_ACTION_COMMAND. */
	public static final String PASTE_ACTION_COMMAND = "Paste";

	/** The Constant RENAME_ACTION_COMMAND. */
	public static final String RENAME_ACTION_COMMAND = "Rename";

	/** The Constant DELETE_ACTION_COMMAND. */
	public static final String DELETE_ACTION_COMMAND = "Delete";

	/** The Constant INVITE_ACTION_COMMAND. */
	public static final String INVITE_ACTION_COMMAND = "Invite";

	/** The Constant DOWNLOAD_ACTION_COMMAND. */
	public static final String DOWNLOAD_ACTION_COMMAND = "Download";

	/** The Constant UPLOAD_ACTION_COMMAND. */
	public static final String UPLOAD_ACTION_COMMAND = "Upload";

	/** The Constant ADDFAVORITES_ACTION_COMMAND. */
	public static final String ADDFAVORITES_ACTION_COMMAND = "AddFavorites";

	/** The Constant OPEN_ACTION_COMMAND. */
	public static final String OPEN_ACTION_COMMAND = "Open";

	/** The Constant PROPERTIES_ACTION_COMMAND. */
	public static final String PROPERTIES_ACTION_COMMAND = "Properties";

	/** The Constant VERSIONS_ACTION_COMMAND. */
	public static final String VERSIONS_ACTION_COMMAND = "Versions";

	/** The Constant PREFERENCES_ACTION_COMMAND. */
	public static final String PREFERENCES_ACTION_COMMAND = "Preferences";

	/** The Constant DETAIL_VIEW_ACTION_COMMAND. */
	public static final String DETAIL_VIEW_ACTION_COMMAND = "DetailView";

	/** The Constant LIST_VIEW_ACTION_COMMAND. */
	public static final String LIST_VIEW_ACTION_COMMAND = "ListView";

	/** The Constant ICON_VIEW_ACTION_COMMAND. */
	public static final String ICON_VIEW_ACTION_COMMAND = "IconView";

	/** The Constant THUMBNAIL_VIEW_ACTION_COMMAND. */
	public static final String THUMBNAIL_VIEW_ACTION_COMMAND = "ThumbnailView";

	/** The Constant RELOAD_ACTION_COMMAND. */
	public static final String RELOAD_ACTION_COMMAND = "Reload";

	/** The Constant RESET_PERSPECTIVE_ACTION_COMMAND. */
	public static final String RESET_PERSPECTIVE_ACTION_COMMAND = "ResetPerspective";

	/** The Constant LOCATION_ACTION_COMMAND. */
	public static final String LOCATION_ACTION_COMMAND = "Location";

	/** The Constant UP_ACTION_COMMAND. */
	public static final String UP_ACTION_COMMAND = "Up";

	/** The Constant BACK_ACTION_COMMAND. */
	public static final String BACK_ACTION_COMMAND = "Back";

	/** The Constant FORWARD_ACTION_COMMAND. */
	public static final String FORWARD_ACTION_COMMAND = "Forward";

	/** The Constant HOME_ACTION_COMMAND. */
	public static final String HOME_ACTION_COMMAND = "Home";

	/** The Constant PICASA_LOGIN_ACTION_COMMAND. */
	public static final String PICASA_LOGIN_ACTION_COMMAND = "PicasaLogin";

	/** The Constant PICASA_ADD_ACTION_COMMAND. */
	public static final String PICASA_ADD_ACTION_COMMAND = "PicasaAdd";

	/** The Constant PICASA_MANAGE_ACTION_COMMAND. */
	public static final String PICASA_MANAGE_ACTION_COMMAND = "PicasaManage";

	/** The Constant HELP_CONTENT_ACTION_COMMAND. */
	public static final String HELP_CONTENT_ACTION_COMMAND = "HelpContent";

	/** The Constant TOTD_ACTION_COMMAND. */
	public static final String TOTD_ACTION_COMMAND = "TOTD";

	/** The Constant ABOUT_ACTION_COMMAND. */
	public static final String ABOUT_ACTION_COMMAND = "About";

	/** The Constant DISCONNECT_ACTION_COMMAND. */
	public static final String DISCONNECT_ACTION_COMMAND = "Disconnect";

	/** The Constant SEARCH_ACTION_COMMAND. */
	public static final String SEARCH_ACTION_COMMAND = "Search";

	/** The Constant FAVORITESVIEW_ACTION_COMMAND. */
	public static final String FAVORITESVIEW_ACTION_COMMAND = "FavoritesView";

	/** The Constant HISTORYVIEW_ACTION_COMMAND. */
	public static final String HISTORYVIEW_ACTION_COMMAND = "HistoryView";

	/** The Constant ACTIVATEVERSION_ACTION_COMMAND. */
	public static final String ACTIVATEVERSION_ACTION_COMMAND = "ActivateVersion";

	/** The Constant MODIFMETA_ACTION_COMMAND. */
	public static final String MODIFMETA_ACTION_COMMAND = "ModifMeta";

	/** The Constant CREATEFOLDER_ACTION_COMMAND. */
	public static final String CREATEFOLDER_ACTION_COMMAND = "CreateFolder";

	/** The Constant HELPLINE_ACTION_COMMAND. */
	public static final String HELPLINE_ACTION_COMMAND = "HelpLine";

	/** The Constant DEFAULT_PERSPECTIVE. */
	private static final String DEFAULT_PERSPECTIVE = "default.perspective";

	/** The Constant DOCKING_LIST_VIEW. */
	public static final String DOCKING_LIST_VIEW = "listview.view";

	/** The Constant DOCKING_TREE_VIEW. */
	public static final String DOCKING_TREE_VIEW = "treeview.view";

	/** The Constant DOCKING_PREVIEW_VIEW. */
	private static final String DOCKING_PREVIEW_VIEW = "preview.view";

	/** The Constant DOCKING_PLUGIN_VIEW. */
	public static final String DOCKING_PLUGIN_VIEW = "plugin.view";

	/** The Constant DOCKING_BOOKMARK_VIEW. */
	public static final String DOCKING_BOOKMARK_VIEW = "bookmark.view";

	/** The Constant DOCKING_HISTORY_VIEW. */
	public static final String DOCKING_HISTORY_VIEW = "history.view";

	/** The Constant DOCKING_SEARCH_VIEW. */
	public static final String DOCKING_SEARCH_VIEW = "search.view";

	/** The button copy. */
	private JButton buttonCopy;

	/** The button cut. */
	private JButton buttonCut;

	/** The button paste. */
	private JButton buttonPaste;

	/** The button download. */
	private JButton buttonDownload;

	/** The ba open. */
	private BrowserAction baOpen;

	/** The ba download. */
	private BrowserAction baDownload;

	/** The ba cut. */
	private BrowserAction baCut;

	/** The ba copy. */
	private BrowserAction baCopy;

	/** The ba paste. */
	private BrowserAction baPaste;

	/** The ba rename. */
	private BrowserAction baRename;

	/** The ba delete. */
	private BrowserAction baDelete;

	/** The ba invite. */
	private BrowserAction baInvite;

	/** The ba prop. */
	private BrowserAction baProp;

	/** The ba versions. */
	private BrowserAction baVersions;

	/** The ba favorite. */
	private BrowserAction baFavorite;

	/** The bundle. */
	private ResourceBundle bundle = ResourceBundle.getBundle("kiyut.ekspos.BrowserWindow",SessionHandler.getLocale());

	/** The viewport. */
	private Viewport viewport;

	/** The shell tree view. */
	private CmisObjectTreeView shellTreeView;

	/** The shell list view. */
	private CmisObjectListView shellListView;

	/** The image preview pane. */
	private ImagePane imagePreviewPane;

	/** The viewer. */
	private CmisViewer viewer;

	/** The tool bar. */
	private JToolBar toolBar;



	/** The mgr. */
	public PerspectiveManager mgr;

	/** The map view plugins. */
	public Map<String,View> mapViewPlugins;

	/** The shell progress monitor. */
	private CmisProgressMonitor shellProgressMonitor;

	//menu file
	/** The shell tree view popup menu. */
	private JPopupMenu shellTreeViewPopupMenu;

	/** The shell list view popup menu. */
	private JPopupMenu shellListViewPopupMenu;

	//menu folder
	/** The shell tree view popup menu folder. */
	private JPopupMenu shellTreeViewPopupMenuFolder;

	/** The shell list view popup menu folder. */
	private JPopupMenu shellListViewPopupMenuFolder;

	/** The shell tree view scroll. */
	private JScrollPane shellTreeViewScroll = new JScrollPane();

	/** The status bar. */
	private StatusBar statusBar;

	/** The Constant HISTORY_SIZE. */
	private static final int HISTORY_SIZE = 9;

	/** The history list. */
	private List<String> historyList = new ArrayList<String>(HISTORY_SIZE);

	/** The location combo. */
	private JComboBox locationCombo;

	/** The location list. */
	private List<String> locationList = new ArrayList<String>(HISTORY_SIZE);


	/** The shell list view in progress. */
	private boolean shellListViewInProgress = false;

	/** The shell tree view in progress. */
	private boolean shellTreeViewInProgress = false;

	/** The back or forward in progress. */
	public  boolean backOrForwardInProgress = false;

	/** The already back. */
	private boolean alreadyBack = false;

	/** The history index. */
	private int historyIndex = 0;

	//copy paste
	/** The selected list. */
	private List<CmisObject> selectedList;

	/** The copy. */
	private boolean copy=false;

	/** The cut. */
	private boolean cut=false;

	/** The source cut copy. */
	private Folder sourceCutCopy ; 

	/** The action map. */
	private Map<String,Action> actionMap;

	/** The blacklist. */
	private static List<String> blacklist = null;

	/** The invite users view. */
	private InviteUsersView inviteUsersView;

	/** The instance browser window. */
	private static BrowserWindow instanceBrowserWindow = null;

	/** The my status progress bar. */
	public static MyProgressBar myStatusProgressBar = new MyProgressBar();

	//elements pour la recherche
	/** The text_fast_search. */
	private JTextField text_fast_search;

	/** The search window. */
	private SearchWindow searchWindow;


	/**
	 * Gets the single instance of BrowserWindow.
	 *
	 * @return single instance of BrowserWindow
	 */
	public static BrowserWindow getInstance() {
		if (instanceBrowserWindow == null) {
			instanceBrowserWindow = new BrowserWindow();
		}
		return instanceBrowserWindow;
	}

	/**
	 * Instantiates a new browser window.
	 */
	private BrowserWindow() {

		setTitle(Application.getLongName());
		setIconImage(Application.getIconImage());

		mapViewPlugins = new HashMap<String, View>();
		BrowseWindowPreferences prefs = BrowseWindowPreferences.getInstance();
		int x = prefs.getX();
		int y = prefs.getY();
		int width = prefs.getWidth();
		int height = prefs.getHeight();

		this.setSize(width,height);
		if (!(x < 0 || y < 0)) {
			this.setBounds(x,y,width,height);
		}

		JPanel contentPane = new JPanel();
		contentPane.setLayout(new BorderLayout());
		setContentPane(contentPane);

		try {
			shellTreeView  = new CmisObjectTreeView("");
		} catch (FileNotFoundException e) {
			ExceptionUtils.createJXErrorIOException(e, contentPane);
		} catch (SecurityException e) {
			JXErrorPane.showDialog(contentPane, new ErrorInfo(e.getMessage(), 
					e.getMessage(), 
					null, "SecurityException", e, Level.WARNING, null)); 
		}

		shellListView = new CmisObjectListView();
		imagePreviewPane = new ImagePane();

		shellListView.setTransferHandler(new CmisObjectTransferHandler());
		shellListView.setDragEnabled(true);

		imagePreviewPane.setBorder(new EmptyBorder(3,3,3,3));

		shellTreeView.addTreeSelectionListener(new javax.swing.event.TreeSelectionListener() {
			public void valueChanged(TreeSelectionEvent evt) {
				shellTreeViewValueChanged(evt);
			}
		});

		shellListView.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
			public void valueChanged(ListSelectionEvent evt) {
				shellListViewValueChanged(evt);
			}
		});

		shellListView.addListDataListener(new javax.swing.event.ListDataListener() {
			public void contentsChanged(ListDataEvent evt) {
				shellListViewContentsChanged(evt);
			}
			public void intervalAdded(ListDataEvent evt) {}
			public void intervalRemoved(ListDataEvent evt) {}
		});

		shellListView.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent evt) { 
				shellListViewMouseClicked(evt); }
		});

		shellProgressMonitor = new CmisProgressMonitor(this);
		shellProgressMonitor.addShellListener(new ShellAdapter() {
			@Override
			public void shellDeleted(ShellEvent evt) {  shellProgressMonitorShellDeleted(evt); }
			@Override
			public void shellMoved(ShellEvent evt) {  shellProgressMonitorShellMoved(evt); }
		});


		shellTreeViewScroll.setViewportView(shellTreeView);
		shellTreeViewScroll.getViewport().setBackground(shellTreeView.getBackground());

		statusBar = new StatusBar();
		StatusBarItem statusBarItem = new StatusBarItem(" ",100,SwingConstants.CENTER);
		myStatusProgressBar.setSize(100, 20);
		statusBarItem.add(myStatusProgressBar);
		statusBar.addItem(statusBarItem);
		statusBarItem = new StatusBarItem(" ",150,SwingConstants.LEFT);
		statusBar.addItem(statusBarItem);
		contentPane.add(statusBar,BorderLayout.SOUTH);

		initActions();
		restoreFromPreferences();

		// need to put inside try..catch because docking is problematic
		try {
			initDocking();
		} catch (Exception ex) {
		}

	}



	/**
	 * Inits the actions.
	 */
	private void initActions() {
		actionMap = new HashMap<String,Action>();

		// create action
		actionMap.put(EXIT_ACTION_COMMAND,new BrowserAction(EXIT_ACTION_COMMAND));
		baCut = new BrowserAction(CUT_ACTION_COMMAND);
		baCut.setEnabled(false);
		actionMap.put(CUT_ACTION_COMMAND,baCut);
		baCopy = new BrowserAction(COPY_ACTION_COMMAND);
		baCopy.setEnabled(false);
		actionMap.put(COPY_ACTION_COMMAND,baCopy);
		baPaste = new BrowserAction(PASTE_ACTION_COMMAND);
		if((copy==true)||(cut==true))
			baPaste.setEnabled(true);
		else baPaste.setEnabled(false);
		actionMap.put(PASTE_ACTION_COMMAND,baPaste);
		baRename = new BrowserAction(RENAME_ACTION_COMMAND);
		baRename.setEnabled(false);
		actionMap.put(RENAME_ACTION_COMMAND,baRename);
		baDelete = new BrowserAction(DELETE_ACTION_COMMAND);
		baDelete.setEnabled(false);
		actionMap.put(DELETE_ACTION_COMMAND,baDelete);
		actionMap.put(PREFERENCES_ACTION_COMMAND,new BrowserAction(PREFERENCES_ACTION_COMMAND));
		actionMap.put(DETAIL_VIEW_ACTION_COMMAND,new BrowserAction(DETAIL_VIEW_ACTION_COMMAND));
		actionMap.put(LIST_VIEW_ACTION_COMMAND,new BrowserAction(LIST_VIEW_ACTION_COMMAND));
		actionMap.put(ICON_VIEW_ACTION_COMMAND,new BrowserAction(ICON_VIEW_ACTION_COMMAND));
		actionMap.put(THUMBNAIL_VIEW_ACTION_COMMAND,new BrowserAction(THUMBNAIL_VIEW_ACTION_COMMAND));
		actionMap.put(RELOAD_ACTION_COMMAND,new BrowserAction(RELOAD_ACTION_COMMAND));
		actionMap.put(RESET_PERSPECTIVE_ACTION_COMMAND,new BrowserAction(RESET_PERSPECTIVE_ACTION_COMMAND));
		actionMap.put(LOCATION_ACTION_COMMAND,new BrowserAction(LOCATION_ACTION_COMMAND));
		actionMap.put(UP_ACTION_COMMAND,new BrowserAction(UP_ACTION_COMMAND));
		actionMap.put(BACK_ACTION_COMMAND,new BrowserAction(BACK_ACTION_COMMAND));
		actionMap.put(FORWARD_ACTION_COMMAND,new BrowserAction(FORWARD_ACTION_COMMAND));
		actionMap.put(HOME_ACTION_COMMAND,new BrowserAction(HOME_ACTION_COMMAND));
		actionMap.put(PICASA_LOGIN_ACTION_COMMAND,new BrowserAction(PICASA_LOGIN_ACTION_COMMAND));
		actionMap.put(PICASA_ADD_ACTION_COMMAND,new BrowserAction(PICASA_ADD_ACTION_COMMAND));
		actionMap.put(PICASA_MANAGE_ACTION_COMMAND,new BrowserAction(PICASA_MANAGE_ACTION_COMMAND));
		actionMap.put(HELP_CONTENT_ACTION_COMMAND,new BrowserAction(HELP_CONTENT_ACTION_COMMAND));
		actionMap.put(TOTD_ACTION_COMMAND,new BrowserAction(TOTD_ACTION_COMMAND));
		actionMap.put(ABOUT_ACTION_COMMAND,new BrowserAction(ABOUT_ACTION_COMMAND));
		baInvite = new BrowserAction(INVITE_ACTION_COMMAND);
		baInvite.setEnabled(false);
		actionMap.put(INVITE_ACTION_COMMAND,baInvite);
		baFavorite = new BrowserAction(ADDFAVORITES_ACTION_COMMAND);
		baFavorite.setEnabled(false);
		actionMap.put(ADDFAVORITES_ACTION_COMMAND,baFavorite);
		baOpen = new BrowserAction(OPEN_ACTION_COMMAND);
		baOpen.setEnabled(false);
		actionMap.put(OPEN_ACTION_COMMAND,baOpen);
		baVersions = new BrowserAction(VERSIONS_ACTION_COMMAND);
		baVersions.setEnabled(false);
		actionMap.put(VERSIONS_ACTION_COMMAND,baVersions);
		baDownload = new BrowserAction(DOWNLOAD_ACTION_COMMAND);
		baDownload.setEnabled(false);
		actionMap.put(DOWNLOAD_ACTION_COMMAND,baDownload);
		actionMap.put(UPLOAD_ACTION_COMMAND,new BrowserAction(UPLOAD_ACTION_COMMAND));
		baProp = new BrowserAction(PROPERTIES_ACTION_COMMAND);
		baProp.setEnabled(false);
		actionMap.put(PROPERTIES_ACTION_COMMAND,baProp);
		actionMap.put(DISCONNECT_ACTION_COMMAND, new BrowserAction(DISCONNECT_ACTION_COMMAND));
		actionMap.put(SEARCH_ACTION_COMMAND, new BrowserAction(SEARCH_ACTION_COMMAND)); 
		actionMap.put(FAVORITESVIEW_ACTION_COMMAND, new BrowserAction(FAVORITESVIEW_ACTION_COMMAND)); 
		actionMap.put(HISTORYVIEW_ACTION_COMMAND, new BrowserAction(HISTORYVIEW_ACTION_COMMAND)); 
		actionMap.put(ACTIVATEVERSION_ACTION_COMMAND, new BrowserAction(ACTIVATEVERSION_ACTION_COMMAND)); 
		actionMap.put(MODIFMETA_ACTION_COMMAND, new BrowserAction(MODIFMETA_ACTION_COMMAND)); 
		actionMap.put(CREATEFOLDER_ACTION_COMMAND, new BrowserAction(CREATEFOLDER_ACTION_COMMAND)); 
		actionMap.put(HELPLINE_ACTION_COMMAND, new BrowserAction(HELPLINE_ACTION_COMMAND)); 

		// inititalize action from ResourceBundle
		MenuFactory.configureActionMap(bundle,actionMap);

		// initialize menuBarf
		JMenuBar menuBar = MenuFactory.createMenuBar(bundle,actionMap);
		setJMenuBar(menuBar);

		// initialize navigation toolBar
		JPanel toolBarPane = new JPanel();
		toolBarPane.setLayout(new BorderLayout());
		getContentPane().add(toolBarPane, BorderLayout.NORTH);

		toolBar = new JToolBar();
		toolBar.setFloatable(false);
		toolBar.setRollover(true);
		toolBarPane.add(toolBar,BorderLayout.WEST);

		toolBar.add(createToolBarButton(actionMap.get(BACK_ACTION_COMMAND)));
		toolBar.add(createToolBarButton(actionMap.get(FORWARD_ACTION_COMMAND)));
		toolBar.add(createToolBarButton(actionMap.get(UP_ACTION_COMMAND)));
		toolBar.add(createToolBarButton(actionMap.get(HOME_ACTION_COMMAND)));
		toolBar.add(createToolBarButton(actionMap.get(RELOAD_ACTION_COMMAND)));
		toolBar.addSeparator();
		toolBar.add(createToolBarButton(actionMap.get(ABOUT_ACTION_COMMAND)));

		JPanel searchPane = new JPanel(new FlowLayout());

		text_fast_search = new JTextField(15);
		text_fast_search.setMaximumSize(new Dimension(100,20));
		text_fast_search.addKeyListener(new KeyAdapter() {
			
			@Override
			public void keyPressed(KeyEvent e) {
				int keyCode = e.getKeyCode();
				if (keyCode==KeyEvent.VK_ENTER) {        
					search(text_fast_search.getText());
		        } 
			}
			
		});
		
		searchPane.add(text_fast_search);
		JButton buttonSearch = createToolBarButton(actionMap.get(SEARCH_ACTION_COMMAND));
		buttonSearch.setMaximumSize(new Dimension(100,20));
		searchPane.add(buttonSearch);

		toolBarPane.add(searchPane,BorderLayout.EAST);

		// initialize address toolBar
		JToolBar toolBarAdresse = new JToolBar();
		toolBarAdresse.setFloatable(false);
		toolBarAdresse.setRollover(true);
		toolBarPane.add(toolBarAdresse,BorderLayout.SOUTH);


		JLabel locationLabel = new JLabel(bundle.getString("Location.text")+" ");

		locationCombo = new JComboBox();
		locationCombo.addItem(CmisObjectListViewModel.CMIS_USER_HOME);
		locationCombo.setEditable(true);
		Action action = actionMap.get(LOCATION_ACTION_COMMAND);
		locationCombo.setActionCommand((String)action.getValue(Action.ACTION_COMMAND_KEY));
		locationCombo.setAction(action);

		toolBarAdresse.add(locationLabel);
		toolBarAdresse.add(locationCombo);


		////////////////////
		// ShellTreeView
		///////////////////
		shellTreeViewPopupMenu = MenuFactory.createPopupMenu(bundle,actionMap,"ShellTreeViewPopupMenu");
		shellTreeViewPopupMenuFolder = MenuFactory.createPopupMenu(bundle,actionMap,"ShellTreeViewPopupMenuFolder");
		shellTreeView.addMouseListener(new java.awt.event.MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent evt) {}
			@Override
			public void mousePressed(MouseEvent evt) { shellTreeViewPopupTrigger(evt); }
			@Override
			public void mouseReleased(MouseEvent evt) { shellTreeViewPopupTrigger(evt); }
		});

		shellTreeView.getCellEditor().addCellEditorListener(new javax.swing.event.CellEditorListener() {
			public void editingStopped(ChangeEvent evt) { shellTreeViewEditingStopped(evt); }
			public void editingCanceled(ChangeEvent evt)  { shellTreeViewEditingStopped(evt); }
		});


		////////////////////
		// ShellListView
		///////////////////
		shellListViewPopupMenu = MenuFactory.createPopupMenu(bundle,actionMap,"ShellListViewPopupMenu");
		shellListViewPopupMenuFolder = MenuFactory.createPopupMenu(bundle,actionMap,"ShellListViewPopupMenuFolder");
		shellListView.addMouseListener(new java.awt.event.MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent evt) {
				clickedRightSelectedFile(evt);
			}
			@Override
			public void mousePressed(MouseEvent evt) { 
				clickedRightSelectedFile(evt);
				//shellListViewPopupTrigger(evt); 
			}
			@Override
			public void mouseReleased(MouseEvent evt) { 
				clickedRightSelectedFile(evt);	
				//shellListViewPopupTrigger(evt); 
			}

		});

		shellListView.addCellEditorListener(new javax.swing.event.CellEditorListener() {
			public void editingStopped(ChangeEvent evt) { shellListViewEditingStopped(evt); }
			public void editingCanceled(ChangeEvent evt)  { }
		});

		inviteUsersView = new InviteUsersView(shellListView, this);
	}

	/**
	 * Creates the tool bar button.
	 *
	 * @param action the action
	 * @return the j button
	 */
	private JButton createToolBarButton(Action action) {
		JButton button = new JButton(action);
		button.setText("");
		button.setFocusable(false);
		return button;
	}

	/**
	 * Inits the docking.
	 */
	private void initDocking() {
		// create docking view
		JPanel contentPane = (JPanel)getContentPane();

		viewport = new Viewport();
		contentPane.add(viewport, BorderLayout.CENTER);

		// setup the DockingManager to work with our application
		DockingManager.setDockableFactory(new ViewFactory());
		DockingManager.setMainDockingPort(this,"BrowserWindow");

		PerspectiveManager.setFactory(new BrowserPerspectiveFactory());
		PerspectiveManager.setRestoreFloatingOnLoad(false);

		mgr = PerspectiveManager.getInstance();
		mgr.setCurrentPerspective(DEFAULT_PERSPECTIVE, false);
		mgr.reset(this);

		if (ClientModel.perspective_restored_ok) {
			try {
				DockingManager.restoreLayout(true);
				focusOnFilesTab();
			} catch (IOException e) {
				ExceptionUtils.createJXErrorIOException(e, BrowserWindow.getInstance());
			} catch (PersistenceException e) {
				ExceptionUtils.createJXErrorException(e, BrowserWindow.getInstance());
			}
		}

	}

	/**
	 * Restore docking.
	 */
	public void restoreDocking() {
		BrowseWindowPreferences framePrefs = BrowseWindowPreferences.getInstance();
		int frameState = framePrefs.getExtendedState();

		if (Toolkit.getDefaultToolkit().isFrameStateSupported(frameState) == true) {
			this.setExtendedState(frameState);
			// wait till extendedState really done
			do  {
				try {
					Thread.sleep(200);
				} catch (InterruptedException ex) { 
				}         
			} while (frameState != this.getExtendedState() && this.isValid());
		}

		try {
			DockingManager.loadLayoutModel();
			if (ClientModel.perspective_restored_ok) {
				DockingManager.restoreLayout(true);
				focusOnFilesTab();
			}
		} catch(Exception ex) {
			ex.printStackTrace(System.err);
		}

		if (!(shellTreeView.isDisplayable() && shellListView.isDisplayable() && imagePreviewPane.isDisplayable())) {
			resetPerspective();
			System.err.println("[Ekspos] restoreDocking reset perspective");

		}
	}

	/**
	 * Reset perspective.
	 */
	private void resetPerspective() {
		PerspectiveManager mgr = PerspectiveManager.getInstance();
		mgr.remove(DEFAULT_PERSPECTIVE);
		mgr.setCurrentPerspective(DEFAULT_PERSPECTIVE, false);
		mgr.reset(this);

		if (ClientModel.perspective_restored_ok) {
			try {
				DockingManager.restoreLayout(true);
				focusOnFilesTab();
			} catch (IOException e) {
				ExceptionUtils.createJXErrorIOException(e, BrowserWindow.getInstance());
			} catch (PersistenceException e) {
				ExceptionUtils.createJXErrorException(e, BrowserWindow.getInstance());
			}
		}
	}
	
	/**
	 * Reset perspective.
	 */
	private void resetPerspectiveperformed() {
		PerspectiveManager mgr = PerspectiveManager.getInstance();
		mgr.remove(DEFAULT_PERSPECTIVE);
		mgr.setCurrentPerspective(DEFAULT_PERSPECTIVE, false);
		mgr.reset(this);
		View v3 = mapViewPlugins.get(BrowserWindow.DOCKING_TREE_VIEW);
		if(v3 != null) {
			if(v3.getParent() instanceof JTabbedPane){
				JTabbedPane tabbedPane = (JTabbedPane)v3.getParent();
				tabbedPane.setSelectedIndex(0);
				tabbedPane.setTabPlacement(JTabbedPane.TOP);
			}
		}
	}
	/**
	 * Restore from preferences.
	 */
	public void restoreFromPreferences() {
		GeneralPreferences generalPrefs = GeneralPreferences.getInstance();
		IIOPreferences iioPrefs = IIOPreferences.getInstance();

		boolean useCache = generalPrefs.getBoolean(GeneralPreferences.USE_CACHE_KEY);
		CmisThumbnailView thumbnailView = shellListView.getThumbnailView();
		if (useCache == true) {
			String str = GeneralPreferences.getInstance().getString(GeneralPreferences.CACHE_DIRECTORY_KEY);
			File cacheDirectory = new File(str);
			if (cacheDirectory.exists() == false) {
				cacheDirectory.mkdirs();
			}
			thumbnailView.setCacheDirectory(cacheDirectory);
		}
		thumbnailView.setUseCache(useCache);
		thumbnailView.setImageReaderWriterPreferences(iioPrefs.getImageReaderWriterPreferences());
	}


	/* (non-Javadoc)
	 * @see javax.swing.JFrame#processWindowEvent(java.awt.event.WindowEvent)
	 */
	@Override
	protected void processWindowEvent(WindowEvent evt) {
		if (evt.getID() == WindowEvent.WINDOW_CLOSING) {
			exitForm();
		}
	} 

	/**
	 * Exit form.
	 */
	private void exitForm() {
		confirmDisconnect();
	}

	/**
	 * Save prefs.
	 */
	private void savePrefs() {
		BrowseWindowPreferences windowPrefs = BrowseWindowPreferences.getInstance();
		windowPrefs.setExtendedState(this.getExtendedState());
		if (this.getExtendedState() != JFrame.NORMAL) {
			windowPrefs.setBounds(-1,-1,760,500);
		} else {
			Rectangle rv = getBounds();
			windowPrefs.setBounds(rv);
		}
		windowPrefs.save();

		try {
			DockingManager.storeLayoutModel();
		} catch(Exception ex) {
			ex.printStackTrace(System.err);
		}
	}

	/**
	 * Sets the view style.
	 *
	 * @param viewStyle the new view style
	 */
	public void setViewStyle(int viewStyle) {
		shellListView.setViewStyle(viewStyle);
	}

	/**
	 * Sets the viewer.
	 *
	 * @param viewer the new viewer
	 */
	public void setViewer(CmisViewer viewer) {
		this.viewer = viewer;
	}

	/**
	 * Open viewer window.
	 */
	protected void openViewerWindow() {
		if (viewer == null) { return; }

		List<CmisObject> files = shellListView.getSelectedFiles();
		if (files != null) {
			if (files.size() == 1) {
				if (BaseTypeId.CMIS_FOLDER.equals(files.get(0).getBaseTypeId())) { return; }

				files = shellListView.getAllFiles();
			}

			if (files.size() <= 0) {
				return;
			}

			CmisObject file = shellListView.getLastSelectedFile();
			int indexOf = files.indexOf(file);
			if (indexOf < 0) {
				indexOf = 0;
			}

			final List<CmisObject> fileList = files;
			final int index = indexOf;

			//WindowManager.getInstance().openViewerWindow(fileList, index);
			viewer.view(fileList, index);
		}
	}

	/**
	 * Update location model.
	 *
	 * @param file the file
	 */
	public synchronized void updateLocationModel(CmisObject file) {
		//aba historisation
		Folder folder = (Folder)file;
		String pathString = folder.getPath();

		// location stuff
		int index = locationList.indexOf(pathString);
		if (index > -1) {
			locationList.remove(index);
			locationList.add(0,pathString);
		} else {
			locationList.add(0,pathString);
			if (locationList.size() > HISTORY_SIZE) {
				locationList.remove(HISTORY_SIZE-1);
			}
		}

		locationCombo.removeAllItems();
		for (int i=0; i<locationList.size(); i++) {
			locationCombo.addItem(locationList.get(i)); //aba history
		}
	}

	/**
	 * Update history.
	 *
	 * @param file the file
	 */
	protected synchronized void updateHistory(CmisObject file) {
		//aba story
		Folder folder = (Folder)file;
		String pathString = folder.getPath();
		if (backOrForwardInProgress == true) { return; }

		// history stuff
		boolean append = true;
		if (historyList.size() > 0) {
			String str = historyList.get(0);

			//aba
			if (str.equals(pathString)) {
				append = false;
			}
		}
		if (append == true) {
			historyList.add(0,pathString);
		}
		while (historyList.size() > HISTORY_SIZE) {
			historyList.remove(historyList.size()-1);
		}
	}

	/**
	 * Display error file not exists.
	 *
	 * @param file the file
	 */
	protected void displayErrorFileNotExists(String file) {
		Object[] args = {file};
		JOptionPane.setDefaultLocale(SessionHandler.getLocale());
		JOptionPane.showMessageDialog(this,MessageFormat.format(bundle.getString("message.fileNotExists.text"),args),bundle.getString("message.fileNotExists.title"), JOptionPane.ERROR_MESSAGE);
	}

	/////////////////////////////
	// Event Handler
	////////////////////////////
	/**
	 * Shell tree view value changed.
	 *
	 * @param e the e
	 */
	private void shellTreeViewValueChanged(TreeSelectionEvent e) {
		if (shellTreeViewInProgress == true) { return; }

		shellTreeViewInProgress = true;
		try {
			if (!shellListViewInProgress) {
				CmisObject dir = shellTreeView.getLastSelection();
				if (dir != null) {
					shellListView.setCurrentDirectory(dir);
					shellListView.refresh();
				}
			}
		} finally {
			shellTreeViewInProgress = false;
		}
	}

	/**
	 * Shell tree view popup trigger.
	 *
	 * @param evt the evt
	 */
	private void shellTreeViewPopupTrigger(MouseEvent evt) {
		List<CmisObject> files = shellListView.getSelectedFiles();
		if (files == null) {
			return;
		}
		if (evt.isPopupTrigger()) {
			CmisObject file = shellListView.getCurrentDirectory();
			if(BaseTypeId.CMIS_DOCUMENT.equals(file.getBaseTypeId())){
				shellTreeViewPopupMenu.show(evt.getComponent(),evt.getX(), evt.getY());
			}else if(BaseTypeId.CMIS_FOLDER.equals(file.getBaseTypeId())){
				shellTreeViewPopupMenuFolder.show(evt.getComponent(),evt.getX(), evt.getY());
			}    
		}
	}

	/**
	 * Shell tree view editing stopped.
	 *
	 * @param evt the evt
	 */
	private void shellTreeViewEditingStopped(ChangeEvent evt) {

		TreeCellEditor editor = shellTreeView.getCellEditor();
		CmisObjectTreeNode node = (CmisObjectTreeNode)shellTreeView.getLastSelectedPathComponent();

		if(node==null) return;

		CmisObject file = (CmisObject)node.getCmisObject();

		boolean success = false;
		try {

			Map<String,String> modifyFolderProps = new HashMap<String, String>();

			for(Property<?> p :file.getProperties()){
				modifyFolderProps.put(p.getId(),p.getValueAsString());
			}

			modifyFolderProps.put(PropertyIds.NAME,editor.getCellEditorValue().toString());
			file.updateProperties(modifyFolderProps,true);

			success = true;

		} catch (Exception ex) {
			success = false;
		}

		if (success == true) {
			node.setCmisObject(file);
			CmiSObjectTreeModel dataModel = (CmiSObjectTreeModel)shellTreeView.getModel();
			dataModel.reload(node);
			TreeSelectionModel selectionModel = shellTreeView.getSelectionModel();
			selectionModel.clearSelection();
			selectionModel.setSelectionPath(new TreePath(node.getPath()));
		} else {
			JOptionPane.setDefaultLocale(SessionHandler.getLocale());
			JOptionPane.showMessageDialog(this, bundle.getString("message.renameException.text"), bundle.getString("message.exception.title"), JOptionPane.ERROR_MESSAGE);
		}
	}

	/**
	 * Shell list view value changed.
	 *
	 * @param evt the evt
	 */
	private void shellListViewValueChanged(ListSelectionEvent evt) {

		List<CmisObject> selectedItem = shellListView.getSelectedFiles();
		if(selectedItem==null) {
			buttonCopy.setEnabled(false);
			buttonDownload.setEnabled(false);
			buttonCut.setEnabled(false);
			if((cut==true) || (copy==true)){
				buttonPaste.setEnabled(true);
				baPaste.setEnabled(true);
			}
			else {
				buttonPaste.setEnabled(false);
				baPaste.setEnabled(false);
			}
			baCopy.setEnabled(false);
			baCut.setEnabled(false);
			baRename.setEnabled(false);
			baDelete.setEnabled(false);
			baInvite.setEnabled(false);
			baFavorite.setEnabled(false);
			baVersions.setEnabled(false);
			baProp.setEnabled(false);
			return;
		}
		imagePreviewPane.setProgressRepaint(GeneralPreferences.getInstance().getDouble(GeneralPreferences.PROGRESS_REPAINT_KEY));

		boolean containsFolder = false;

		for(CmisObject files : selectedItem){
			if(files instanceof Folder){
				containsFolder=true;
				break;
			}
		}

		if(containsFolder){
			baOpen.setEnabled(false);
			baDownload.setEnabled(false);
			baCut.setEnabled(true);
			baCopy.setEnabled(false);
			if((copy==true)||(cut==true))
				baPaste.setEnabled(true);
			else baPaste.setEnabled(false);
			baRename.setEnabled(true);
			baDelete.setEnabled(true);
			baInvite.setEnabled(true);
			baFavorite.setEnabled(true);
			baVersions.setEnabled(true);
			baProp.setEnabled(true);
		} else {
			baOpen.setEnabled(true);
			baDownload.setEnabled(true);
			buttonDownload.setEnabled(true);
			baCut.setEnabled(true);
			baCopy.setEnabled(true);
			if((copy==true)||(cut==true))
				baPaste.setEnabled(true);
			else baPaste.setEnabled(false);
			baRename.setEnabled(true);
			baDelete.setEnabled(true);
			baInvite.setEnabled(true);
			baFavorite.setEnabled(true);
			baVersions.setEnabled(true);
			baProp.setEnabled(true);
		}
	}

	/**
	 * Shell list view contents changed.
	 *
	 * @param evt the evt
	 */
	private void shellListViewContentsChanged(ListDataEvent evt) {
		if (shellListViewInProgress == true) { 
			baPaste.setEnabled(false);
			baCut.setEnabled(false);
			baCopy.setEnabled(false);
			baRename.setEnabled(false);
			baDelete.setEnabled(false);
			return; }

		if (evt.getIndex0() != CmisObjectListViewModel.ALL_INDEX && evt.getIndex1() != CmisObjectListViewModel.ALL_INDEX) {
			return;
		}

		shellListViewInProgress = true;
		try {
			// synchronize with folder tree
			CmisObject dir = shellListView.getCurrentDirectory();
			if (!shellTreeViewInProgress) {
				shellTreeView.setSelection(dir);
			}

			// synchronize with history
			updateLocationModel(dir);
			updateHistory(dir);

			//aba
			if(BaseTypeId.CMIS_FOLDER.equals(dir.getBaseTypeId())) {
				Folder dirDisplay = (Folder) dir;
				locationCombo.setSelectedItem(dirDisplay.getPath());
			}

		} finally {
			shellListViewInProgress = false;
		}

		if (backOrForwardInProgress == false) {
			historyIndex = 0;
		}
	}

	/**
	 * Shell list view popup trigger.
	 *
	 * @param evt the evt
	 */
	private void shellListViewPopupTrigger(MouseEvent evt) {

		List<CmisObject> files = shellListView.getSelectedFiles();
		if (files == null) {
			return;
		}
		if (evt.isPopupTrigger()) {
			CmisObject file = shellListView.getSelectedFiles().get(0);
			if(BaseTypeId.CMIS_DOCUMENT.equals(file.getBaseTypeId())){
				shellListViewPopupMenu.show(evt.getComponent(),evt.getX(), evt.getY());
			}else if(BaseTypeId.CMIS_FOLDER.equals(file.getBaseTypeId())){
				shellListViewPopupMenuFolder.show(evt.getComponent(),evt.getX(), evt.getY());
			}    
		}
	}

	/**
	 * Shell list view editing stopped.
	 *
	 * @param evt the evt
	 */
	private void shellListViewEditingStopped(ChangeEvent evt) {
		CellEditor editor = (CellEditor)evt.getSource();
		int index = shellListView.getLastSelectedIndex();

		if (index >= 0) {
			try {
				shellListView.getModel().renameFile(index, editor.getCellEditorValue().toString());
				shellTreeView.refresh();
			} catch (Exception ex) {
				JOptionPane.setDefaultLocale(SessionHandler.getLocale());
				JOptionPane.showMessageDialog(this, bundle.getString("message.renameException.text"), bundle.getString("message.exception.title"), JOptionPane.ERROR_MESSAGE);
			}
		}
	}

	/**
	 * Shell list view mouse clicked.
	 *
	 * @param evt the evt
	 */
	public void shellListViewMouseClicked(MouseEvent evt) {

		List<CmisObject> selectedItem = shellListView.getSelectedFiles();

		if(selectedItem==null) {
			buttonCopy.setEnabled(false);
			buttonDownload.setEnabled(false);
			buttonCut.setEnabled(false);
			if((cut==true) || (copy==true))
				buttonPaste.setEnabled(true);
			else buttonPaste.setEnabled(false);
			return;
		} 

		for(CmisObject object : selectedItem){
			if (object instanceof Folder) {
				if((cut==true) || (copy==true))
					buttonPaste.setEnabled(true);
				else buttonPaste.setEnabled(false);
				buttonCopy.setEnabled(false);
				buttonDownload.setEnabled(false);
				buttonCut.setEnabled(true);
				break;
			} else {
				buttonCopy.setEnabled(true);
				buttonDownload.setEnabled(true);
				buttonCut.setEnabled(true);
				if((cut==true) || (copy==true))
					buttonPaste.setEnabled(true);
				else buttonPaste.setEnabled(false);
			}
		}
		if (evt.getClickCount() == 2) {
			new Thread() {
				public void run() {
					SwingUtilities.invokeLater(new Runnable() {
						@Override
						public void run() {
							myStatusProgressBar.startTransfer();
						}
					});
					openActionPerformed();
					SwingUtilities.invokeLater(new Runnable() {
						@Override
						public void run() {
							myStatusProgressBar.endTransfer();
						}
					});
				};
			}.start();
		}
	}


	/**
	 * Shell list view key pressed.
	 *
	 * @param evt the evt
	 */
	public void shellListViewKeyPressed(KeyEvent evt) {
		if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
			openViewerWindow();
		}
	}

	/**
	 * History back.
	 */
	private void historyBack() {
		if (historyList.size() < 1) { return; }

		alreadyBack=true;
		backOrForwardInProgress = true;
		try {
			historyIndex++;
			if (historyIndex < historyList.size()) {
				CmisObject file=null;
				try {
					file = SessionHandler.getClientSession().getSession().getObjectByPath(historyList.get(historyIndex));
				} catch (CmisObjectNotFoundException e) {
				} 

				if (file!=null &&  BaseTypeId.CMIS_FOLDER.equals(file.getBaseTypeId())) {
					shellListView.setCurrentDirectory(file);
					shellListView.refresh();
				} else {
					displayErrorFileNotExists(historyList.get(historyIndex));
				}
			} else {
				historyIndex = historyList.size()-1;
			}
		} finally {
			backOrForwardInProgress = false;
		}

	}

	/**
	 * History forward.
	 */
	private void historyForward() {
		if ((historyList.size() <= 1)|| alreadyBack==false) { return; }
		backOrForwardInProgress = true;
		try {
			if (historyIndex > -1) {
				CmisObject file=null;
				try {
					file = SessionHandler.getClientSession().getSession().getObjectByPath(historyList.get(historyIndex+1));
				} catch (CmisObjectNotFoundException e) {
				} 

				if (file!=null &&  BaseTypeId.CMIS_FOLDER.equals(file.getBaseTypeId())) {
					shellListView.setCurrentDirectory(file);

					shellListView.refresh();
				} else {
					displayErrorFileNotExists(historyList.get(historyIndex));
				}
			} else {
				historyIndex = 0;
			}
		} finally {
			backOrForwardInProgress = false;
		}

	}

	/**
	 * Up action performed.
	 */
	private void upActionPerformed() {
		CmisObject dir = shellListView.getCurrentDirectory();
		if (dir != null) {

			if(BaseTypeId.CMIS_DOCUMENT.equals(dir.getBaseTypeId())){
				dir = ((Document)dir).getParents().get(0);
			} else if(BaseTypeId.CMIS_FOLDER.equals(dir.getBaseTypeId())){
				dir = ((Folder)dir).getFolderParent();
			}
		}

		if (dir != null) {
			shellListView.setCurrentDirectory(dir);
			shellListView.refresh();
		} else {

		}
	}

	/**
	 * Location action performed.
	 *
	 * @param str the str
	 */
	private void locationActionPerformed(String str) {
		if (shellListViewInProgress) {
			return;
		}
		CmisObject file=null;
		try {
			file = SessionHandler.getClientSession().getSession().getObjectByPath(str);
		} catch (CmisObjectNotFoundException e) {
		} 

		if (file!=null && BaseTypeId.CMIS_FOLDER.equals(file.getBaseTypeId())) {
			shellListView.setCurrentDirectory(file);
			shellListView.refresh();
		} else {
			displayErrorFileNotExists(str);
		}
	}

	/**
	 * Cut action performed.
	 *
	 * @param evt the evt
	 */
	private void cutActionPerformed(ActionEvent evt) {
		cut = true;
		if (selectedList != null) {
			selectedList.clear();
		}
		// Get the selected files
		selectedList = shellListView.getSelectedFiles();
		sourceCutCopy = (Folder)  shellListView.getCurrentDirectory();

	}

	/**
	 * Copy action performed.
	 *
	 * @param evt the evt
	 */
	private void copyActionPerformed(ActionEvent evt) {
		copy = true;

		if (selectedList != null) {
			selectedList.clear();
		}

		// Get the selected files
		selectedList = shellListView.getSelectedFiles();

		sourceCutCopy = (Folder)  shellListView.getCurrentDirectory();

	}


	/**
	 * Paste.
	 */
	private void paste() {
		Folder target = (Folder)  shellListView.getCurrentDirectory();
		if (target==null)
			return;
		if(copy) {
			if (selectedList != null) {
				for (CmisObject file : selectedList) {
					if(BaseTypeId.CMIS_DOCUMENT.equals(file.getBaseTypeId())) {
						Document doc_to_copy = (Document) file;

						FileOutputStream fos;
						ByteBuffer bb = null;
						try {
							File ftmp = File.createTempFile("filetmp", "tmp");
							fos = new FileOutputStream(ftmp);

							bb = ClientModel.getStreamCmisObject(file);
							fos.write(bb.array());
							ftmp.deleteOnExit();
						} catch (CmisBaseException e) {
							ExceptionUtils.createCmisJXBaseException(e, this);
							return;
						} catch (FileNotFoundException e) {
							ExceptionUtils.createJXFileNotFoundException(e, this);
							return;
						} catch (IOException e) {
							ExceptionUtils.createJXErrorIOException(e, this);
							return;
						}


						String type =  doc_to_copy.getProperty(PropertyIds.CONTENT_STREAM_MIME_TYPE).getValueAsString();

						try {

							ClientModel.createStreamCmisObject(target, file.getName(),type, bb,doc_to_copy);


						} catch (CmisBaseException e) {
							ExceptionUtils.createCmisJXBaseException(e, this);
							return;
						} catch (Exception e) {
							ExceptionUtils.createJXErrorException(e, this);
							return;
						}

						//dont use
					} else if(BaseTypeId.CMIS_FOLDER.equals(file.getBaseTypeId())) {

					}
				}
			}
		} else if (cut) {
			if (selectedList != null) {
				for (CmisObject file : selectedList) {
					if(BaseTypeId.CMIS_DOCUMENT.equals(file.getBaseTypeId())) {

						Document doc_to_cut = (Document) file;
						try {
							doc_to_cut.move(sourceCutCopy,target);
						} catch (CmisContentAlreadyExistsException e) {
							JOptionPane.setDefaultLocale(SessionHandler.getLocale());
							JOptionPane.showMessageDialog(this, MessageFormat.format(bundle.getString("paste.exist.text"),file.getName()), "Error",
									JOptionPane.ERROR_MESSAGE);
							return;
						} catch (CmisBaseException cbe) {
							ExceptionUtils.createCmisJXBaseException(cbe, this);
							return;
						}


					} else if(BaseTypeId.CMIS_FOLDER.equals(file.getBaseTypeId())) {
						Folder folder_to_cut = (Folder) file;;

						try {
							folder_to_cut.move(sourceCutCopy,target);
						} catch (CmisBaseException e) {
							ExceptionUtils.createCmisJXBaseException(e, this);
							return;

						} catch (Exception e) {
							ExceptionUtils.createJXErrorException(e, this);
							return;
						}
					}
				}
			}
		}
		//selectedList = null;
		cut = false;
		copy = false;
	}

	/**
	 * Paste action performed.
	 *
	 * @param evt the evt
	 */
	private void pasteActionPerformed(ActionEvent evt) {		
		new Thread() {
			public void run() {
				SwingUtilities.invokeLater(new Runnable() {
					public void run() {
						myStatusProgressBar.startTransfer();
					}
				});
				paste();
				SwingUtilities.invokeLater(new Runnable() {
					public void run() {
						myStatusProgressBar.endTransfer();
						shellListView.refresh();
					}
				});
			}
		}.start();
	}

	/**
	 * Rename action performed.
	 *
	 * @param evt the evt
	 */
	private void renameActionPerformed(ActionEvent evt) {

		Container parent = ((Component)evt.getSource()).getParent();

		if (shellTreeViewPopupMenuFolder.equals(parent)) {
			DefaultMutableTreeNode node = (DefaultMutableTreeNode)shellTreeView.getLastSelectedPathComponent();
			if (node != null) {
				shellTreeView.startEditingAtPath(new TreePath(node.getPath()));
			}
		} else {
			int i = shellListView.getLastSelectedIndex();
			if ( i != -1) {
				shellListView.editCellAt(i);
			}
		}
	}

	/**
	 * Upload action performed.
	 *
	 * @param evt the evt
	 */
	private void uploadActionPerformed(ActionEvent evt) {
		JFileChooser chooser = new JFileChooser();
		chooser.setMultiSelectionEnabled(true);
		ViewComponent viewComp = shellListView;
		CmisObject cmisObject = shellListView.getCurrentDirectory();
		ClientModel cmisClientModel =  viewComp.getViewModel().getModel();
		Folder folder = (FolderImpl) cmisObject;

		int response = chooser.showOpenDialog(shellListView);
		// Save if OK, nothing if Cancel
		if (response == JFileChooser.APPROVE_OPTION) {

			// Get the path of new file
			File[] files = chooser.getSelectedFiles();
			ArrayList<File> fileList =new ArrayList<File>(Arrays.asList(files)); 
			if (files.length==0)
				return;

			try {

				if(SessionHandler.getEnableWizard())
					cmisClientModel.createDocumentsWithProgressBarAndWizard(shellListView, viewComp.getViewModel(),"cmis:document,P:cm:titled,P:cm:author,P:cm:generalclassifiable", fileList, folder, VersioningState.MINOR);
				else 
					cmisClientModel.createDocumentsWithProgressBar(shellListView, viewComp.getViewModel(),"cmis:document,P:cm:titled,P:cm:author,P:cm:generalclassifiable", fileList, folder, VersioningState.MINOR);
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	}

	/**
	 * Download action performed.
	 *
	 * @param evt the evt
	 */
	private void downloadActionPerformed(ActionEvent evt) {

		// Get the name of selected files
		List<CmisObject> selectedList = shellListView.getSelectedFiles();
		ViewComponent viewComp = shellListView;
		ClientModel cmisClientModel =  viewComp.getViewModel().getModel();
		if (selectedList != null) {
			JFileChooser chooser = new JFileChooser();
			int response = -1;
			if ((selectedList.size()==1)&&(BaseTypeId.CMIS_DOCUMENT.equals(selectedList.get(0).getBaseTypeId()))) {
				chooser.setSelectedFile(new File(selectedList.get(0).getName()));
				chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
				response = chooser.showSaveDialog(shellListView);
				// Save if OK, nothing if Cancel
				if (response == JFileChooser.APPROVE_OPTION) {
					cmisClientModel.downloadMultipleCmisObjectWithProgressBar(shellListView, selectedList, chooser.getSelectedFile(), true);
				}
			} else if (selectedList.size()>1) {

				// OS choose the current directory
				chooser.setCurrentDirectory(new File(System.getProperty("user.home")));

				// Set the name in the input field
				chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);

				// Get the user response
				response = chooser.showSaveDialog(shellListView);
				// Save if OK, nothing if Cancel
				if (response == JFileChooser.APPROVE_OPTION) {
					cmisClientModel.downloadMultipleCmisObjectWithProgressBar(shellListView, selectedList, chooser.getSelectedFile(), false);
				}
			}

		}
	}

	/**
	 * Panel informations.
	 *
	 * @param evt the evt
	 * @param index the index
	 * @return the j panel
	 */
	private JPanel panelInformations(ActionEvent evt, int index) {
		CmisObject file = shellListView.getSelectedFiles().get(0);
		return new PanelInformation(file, index);

	}

	/**
	 * Properties action performed.
	 *
	 * @param evt the evt
	 */
	private void propertiesActionPerformed(ActionEvent evt) {
		JFrame mainFrame = new JFrame(bundle.getString("PropertiesInfo.text"));
		mainFrame.getContentPane().add(panelInformations(evt,0));
		mainFrame.setSize(500,400);
		mainFrame.setLocationRelativeTo(this.getParent());
		mainFrame.setVisible(true);
	}

	/**
	 * Addfavorites action performed.
	 *
	 * @param evt the evt
	 */
	private void addfavoritesActionPerformed(ActionEvent evt) {
		if(shellListView.getSelectedFiles()==null){
			return;
		}
		final CmisObject file = shellListView.getSelectedFiles().get(0);
		final JFrame mainFrame = new JFrame(bundle.getString("AddFavorites.text"));
		mainFrame.setIconImage(Toolkit.getDefaultToolkit().createImage(Application.class.getResource("/kiyut/ekspos/favorites.png")));
		mainFrame.setContentPane(new JPanel(new GridLayout()));
		JPanel jPanel = new JPanel(new GridBagLayout());
		GridBagConstraints gbc = new GridBagConstraints();
		
		Insets insets = new Insets(2, 2, 2, 10);
		gbc.insets=insets;
		
		jPanel.add(new JLabel(bundle.getString("NameFavorites.text")),gbc);
		final JTextField field = new JTextField("  "+file.getName()+"   ");
		jPanel.add(field,gbc);
		JButton button = new JButton(bundle.getString("Submit.text"));

		final JTextField fieldTmp = field;
		button.addActionListener(new ActionListener() {

			public void actionPerformed(ActionEvent e) {

				Folder curDir = (Folder) shellListView.getCurrentDirectory();
				try {
					Shortcut.Type type;
					if ("Document".equals(file.getType().getDisplayName()))
						type = Shortcut.Type.Document;
					else
						type = Shortcut.Type.Folder;

					String charSlash = "";

					if(!curDir.getPath().equals("/"))
						charSlash = "/";

					XMLAccess.getInstance().addBookmark(fieldTmp.getText(), type, curDir.getPath()+charSlash + file.getName(), file.getId());

					mainFrame.dispose();
				} catch (XMLNameAlreadyExistException e1) {
					JOptionPane.setDefaultLocale(SessionHandler.getLocale());
					JOptionPane.showMessageDialog(mainFrame, bundle.getString("ExistFavorite.text"));
				}


			}
		});
		jPanel.add(button,gbc);
		mainFrame.setLocationRelativeTo(this);
		mainFrame.getContentPane().add(jPanel);
		mainFrame.pack();
		mainFrame.setVisible(true);
	}

	/**
	 * Invite action performed.
	 *
	 * @param evt the evt
	 */
	private void inviteActionPerformed(ActionEvent evt) {
		try {
			inviteUsersView.inviteDeleteDialog();
		} catch (ArrayIndexOutOfBoundsException e) {
			ErrorInfo info = new ErrorInfo(bundle.getString("invite.FileNotSelected.title"), bundle.getString("invite.FileNotSelected.text"), null, "ArrayIndexOutOfBoundsException", e, Level.WARNING, null);
			JXErrorPane.showDialog(this, info);
		}
	}

	/**
	 * Open action performed.
	 *
	 * @param evt the evt
	 */
	private void openActionPerformed(ActionEvent evt) {
		openActionPerformed();
	}

	/**
	 * Open action performed.
	 */
	private void openActionPerformed() {

		// Get the name of selected files
		List<CmisObject> selectedList = shellListView.getSelectedFiles();
		if (selectedList != null) {
			for (CmisObject file : selectedList) {
				try {
					if (BaseTypeId.CMIS_DOCUMENT.equals(file.getBaseTypeId())) {
						ClientModel.openCmisObject(file);
						Document doc = (Document) file;
						XMLAccess.getInstance().addHistory(file.getName(), Shortcut.Type.Document, doc.getPaths().get(0), file.getId());
					}
				} catch (IOException e) {
					JOptionPane.setDefaultLocale(SessionHandler.getLocale());
					JOptionPane.showMessageDialog(this,
							bundle.getString("OpenImpossible.text"), "Error",
							JOptionPane.ERROR_MESSAGE);
				}

			}
		}
	}

	/**
	 * Versions action performed.
	 *
	 * @param evt the evt
	 */
	private void versionsActionPerformed(ActionEvent evt) {
		JFrame mainFrame = new JFrame(bundle.getString("PropertiesInfo.text"));
		mainFrame.getContentPane().add(panelInformations(evt,2));
		mainFrame.setSize(500,400);
		mainFrame.setLocationRelativeTo(this.getParent());
		mainFrame.setVisible(true);
	}

	/**
	 * Help line action performed.
	 *
	 * @param evt the evt
	 */
	private void helpLineActionPerformed(ActionEvent evt){
		// On vérifie que la classe Desktop soit bien supportée :
		if ( Desktop.isDesktopSupported() ) {
			// On récupère l'instance du desktop :
			Desktop desktop = Desktop.getDesktop();

			// On vérifie que la fonction browse est bien supportée :
			if (desktop.isSupported(Desktop.Action.BROWSE)) {

				// Et on lance l'application associé au protocole :
				try {
					desktop.browse(new URI("https://sites.google.com/site/presgedalfresco/"));
				} catch (IOException e) {
					ExceptionUtils.createJXErrorIOException(e, null);
				} catch (URISyntaxException e) {
					ExceptionUtils.createJXErrorException(e, null);
				}
			}
		}
	}


	/**
	 * Modif meta action performed.
	 *
	 * @param evt the evt
	 */
	private void modifMetaActionPerformed(ActionEvent evt) {

		CmisObject file = shellListView.getSelectedFiles().get(0);
		MetadataWizard.createWizard(file);

	}

	/**
	 * Activate version action performed.
	 *
	 * @param evt the evt
	 */
	private void activateVersionActionPerformed(ActionEvent evt) {
	}

	/**
	 * Creates the folder action performed.
	 *
	 * @param evt the evt
	 */
	private void createFolderActionPerformed(ActionEvent evt){
		getNameNewFolder();
	}

	/**
	 * Delete action performed.
	 *
	 * @param evt the evt
	 */
	private void deleteActionPerformed(ActionEvent evt) {
		JOptionPane.setDefaultLocale(SessionHandler.getLocale());
		//display a message to  delete
		int n = JOptionPane.showConfirmDialog(this,bundle.getString("message.confirmDelete.text"),bundle.getString("message.confirmDelete.title"),JOptionPane.YES_NO_OPTION);
		if (n == JOptionPane.OK_OPTION) {
			new Thread() {
				public void run() {
					SwingUtilities.invokeLater(new Runnable() {
						@Override
						public void run() {
							myStatusProgressBar.startTransfer();
						}
					});
					try {
						// Get the name of selected files
						final List<CmisObject> selectedList = shellListView.getSelectedFiles();
						if (selectedList != null) {
							for (CmisObject file : selectedList) {

								// Get the object to delete on CMIS
								if(BaseTypeId.CMIS_DOCUMENT.equals(file.getBaseTypeId())) {

									((Document)file).deleteAllVersions();

								} else if(BaseTypeId.CMIS_FOLDER.equals(file.getBaseTypeId())) {
									((Folder)file).deleteTree(true, null, true);

								} 
							}
						}
					} catch (CmisPermissionDeniedException cre) {
						ExceptionUtils.createCmisJXPermissionDeniedErrorException(cre, shellListView);
					} catch (CmisBaseException cre) {
						ExceptionUtils.createCmisJXBaseException(cre, shellListView);
					}
					SwingUtilities.invokeLater(new Runnable() {
						@Override
						public void run() {
							myStatusProgressBar.endTransfer();
							shellListView.refresh();
							shellTreeView.refresh();
						}
					});
				};
			}.start();
		}

	}

	/**
	 * Shell progress monitor shell deleted.
	 *
	 * @param evt the evt
	 */
	private void shellProgressMonitorShellDeleted(ShellEvent evt) {
		// handle shellTreeView
		DefaultMutableTreeNode node = (DefaultMutableTreeNode)shellTreeView.getLastSelectedPathComponent();
		if (node != null) {
			if (node.getUserObject().equals(evt.getSourceFile())) {
				CmiSObjectTreeModel dataModel = (CmiSObjectTreeModel)shellTreeView.getModel();
				dataModel.removeNodeFromParent(node);
			}
		}

		// handle shellListView
		if (evt.getSourceFile().equals(shellListView.getCurrentDirectory())) {
		} else {
			CmisObjectListViewModel dataModel = shellListView.getModel();
			int i = dataModel.indexOf(evt.getSourceFile());
			if (i != -1) {
				dataModel.remove(i);
			}
		}
	}

	/**
	 * Shell progress monitor shell moved.
	 *
	 * @param evt the evt
	 */
	private void shellProgressMonitorShellMoved(ShellEvent evt) {
		// handle shellTreeView
		DefaultMutableTreeNode node = (DefaultMutableTreeNode)shellTreeView.getLastSelectedPathComponent();
		if (node != null) {
			if (node.getUserObject().equals(evt.getSourceFile())) {
				CmiSObjectTreeModel dataModel = (CmiSObjectTreeModel)shellTreeView.getModel();
				dataModel.removeNodeFromParent(node);
			}
		}
	}



	/**
	 * The Class BrowserAction.
	 */
	private class BrowserAction extends AbstractAction {

		/** The Constant serialVersionUID. */
		private static final long serialVersionUID = 1L;

		/**
		 * Instantiates a new browser action.
		 *
		 * @param actionCommand the action command
		 */
		public BrowserAction(String actionCommand) {
			putValue(Action.ACTION_COMMAND_KEY,actionCommand);
		}

		/* (non-Javadoc)
		 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
		 */
		public void actionPerformed(ActionEvent evt) {
			myStatusProgressBar.startTransfer();

			try {
				String command = evt.getActionCommand();
				if (command.equals(EXIT_ACTION_COMMAND)) {
					exitForm();

				} else if (command.equals(CUT_ACTION_COMMAND)) {
					cutActionPerformed(evt);
				} else if (command.equals(COPY_ACTION_COMMAND)) {
					copyActionPerformed(evt);
				} else if (command.equals(PASTE_ACTION_COMMAND)) {
					pasteActionPerformed(evt);
				} else if (command.equals(RENAME_ACTION_COMMAND)) {
					renameActionPerformed(evt);
				} else if (command.equals(DELETE_ACTION_COMMAND)) {
					deleteActionPerformed(evt);
				} else if (command.equals(PREFERENCES_ACTION_COMMAND)) {
					WindowManager windowManager = WindowManager.getInstance();
					windowManager.openPreferencesWindow();

				} else if (command.equals(BACK_ACTION_COMMAND)) {
					historyBack();
				} else if (command.equals(FORWARD_ACTION_COMMAND)) {
					historyForward();
				} else if (command.equals(UP_ACTION_COMMAND)) {
					upActionPerformed();
				} else if (command.equals(HOME_ACTION_COMMAND)) {
					shellListView.getModel().setCurrentDirectory(SessionHandler.getClientSession().getSession().getObjectByPath(CmisObjectListViewModel.CMIS_USER_HOME));
					shellListView.refresh();


				} else if (command.equals(RELOAD_ACTION_COMMAND)) {
					shellListView.refresh();
					shellTreeView.refresh();
				} else if (command.equals(LOCATION_ACTION_COMMAND)) {
					JComboBox combo = (JComboBox)evt.getSource();
					String str = (String)combo.getSelectedItem();
					if (str != null) {
						locationActionPerformed(str);
					}
				} else if (command.equals(RESET_PERSPECTIVE_ACTION_COMMAND)) {
					resetPerspectiveperformed();
				} else if (command.equals(DETAIL_VIEW_ACTION_COMMAND)) {
					shellListView.setViewStyle(CmisObjectListView.VS_DETAIL);
				} else if (command.equals(LIST_VIEW_ACTION_COMMAND)) {
					shellListView.setViewStyle(CmisObjectListView.VS_LIST);
				} else if (command.equals(ICON_VIEW_ACTION_COMMAND)) {
					shellListView.setViewStyle(CmisObjectListView.VS_ICON);
				} else if (command.equals(THUMBNAIL_VIEW_ACTION_COMMAND)) {
					shellListView.setViewStyle(CmisObjectListView.VS_THUMBNAIL);

				} else if (command.equals(HELP_CONTENT_ACTION_COMMAND)) {
					JOptionPane.showMessageDialog(BrowserWindow.this,"Not Implemented yet.");
					System.err.println("...Help Contents: not implemented yet");
				} else if (command.equals(TOTD_ACTION_COMMAND)) {
				} else if (command.equals(ABOUT_ACTION_COMMAND)) {
					WindowManager windowManager = WindowManager.getInstance();
					windowManager.openAboutWindow();
				} else if (command.equals(INVITE_ACTION_COMMAND)) {
					inviteActionPerformed(evt);
				} else if (command.equals(UPLOAD_ACTION_COMMAND)) {
					uploadActionPerformed(evt);
				}	else if (command.equals(DOWNLOAD_ACTION_COMMAND)) {
					downloadActionPerformed(evt);
				} else if (command.equals(PROPERTIES_ACTION_COMMAND)) {
					propertiesActionPerformed(evt);
				} else if (command.equals(OPEN_ACTION_COMMAND)) {
					openActionPerformed(evt);
				} else if (command.equals(VERSIONS_ACTION_COMMAND)) {
					versionsActionPerformed(evt);
				} else if (command.equals(ADDFAVORITES_ACTION_COMMAND)) {
					addfavoritesActionPerformed(evt);
				}  else if (command.equals(DISCONNECT_ACTION_COMMAND)) {
					disconnect();
				} else if (command.equals(SEARCH_ACTION_COMMAND)){
					search(text_fast_search.getText());
				} else if (command.equals(FAVORITESVIEW_ACTION_COMMAND)){
				} else if (command.equals(HISTORYVIEW_ACTION_COMMAND)){
				} else if (command.equals(ACTIVATEVERSION_ACTION_COMMAND)){
					activateVersionActionPerformed(evt);
				} else if (command.equals(MODIFMETA_ACTION_COMMAND)){
					modifMetaActionPerformed(evt);
				} else if (command.equals(CREATEFOLDER_ACTION_COMMAND)){
					createFolderActionPerformed(evt);
				} else if (command.equals(HELPLINE_ACTION_COMMAND)){
					helpLineActionPerformed(evt);
				} 
			} catch (CmisBaseException cbe) {
				ExceptionUtils.createCmisJXBaseException(cbe, null);
			} finally {
				myStatusProgressBar.endTransfer();
			}
		}
	}

	/**
	 * Confirm disconnect.
	 */
	public void confirmDisconnect(){
		JOptionPane.setDefaultLocale(SessionHandler.getLocale());
		int exit = JOptionPane.showConfirmDialog(this,
				bundle.getString("TextLogOff.text"),
				bundle.getString("TitleLogOff.text"),
				JOptionPane.OK_CANCEL_OPTION);
		//si l'utilisateur confirme sa deconnexion
		if(exit==JOptionPane.OK_OPTION){
			savePrefs();
			dispose();
			System.exit(0);
		}
	}

	/**
	 * Disconnect.
	 */
	private void disconnect(){
		confirmDisconnect();
	}

	/**
	 * Search.
	 *
	 * @param rapid_search the rapid_search
	 */
	private void search(final String rapid_search){
		new Thread((new Runnable(){

			@Override
			public void run() {
				String search_rapid = rapid_search.trim();
				View v = BrowserWindow.this.mapViewPlugins.get(BrowserWindow.DOCKING_LIST_VIEW);
				if(v!=null){
					if(v.getParent() instanceof JTabbedPane){
						JTabbedPane tabbedPane = (JTabbedPane)v.getParent();
						tabbedPane.setSelectedIndex(1);
						if(!search_rapid.equals("")){
							final InfiniteProgressPanel glassPane = new InfiniteProgressPanel();
							glassPane.setSize(BrowserWindow.this.getWidth(), BrowserWindow.this.getHeight());
							BrowserWindow.this.setGlassPane(glassPane);
							glassPane.start();
							try {
								searchWindow.SetSearchModel(new SearchModel(search_rapid));
								searchWindow.displaySearchResults();
								text_fast_search.setText("");
							} catch (CmisNoResultsException e) {
								glassPane.interrupt();
								JOptionPane.showMessageDialog(BrowserWindow.this, bundle.getString("search_no_results"),
										bundle.getString("search_title"), JOptionPane.INFORMATION_MESSAGE);
							} catch (MalformedCritersException e) {
								glassPane.interrupt();
								JOptionPane.showMessageDialog(BrowserWindow.this, bundle.getString("search_wrong_criters"),
										bundle.getString("search_title"), JOptionPane.ERROR_MESSAGE);
							}
							finally{
								glassPane.interrupt();
							}
						}
						else{
							if(searchWindow.getSearchWindowResult()!=null && searchWindow.getSearchWindowResult().isVisible()){
								searchWindow.getSearchWindowResult().reinitializeSearch();
							}
						}	
					}
				}
			}

		})).start();

	}

	/**
	 * A factory for creating BrowserPerspective objects.
	 */
	private class BrowserPerspectiveFactory implements PerspectiveFactory {

		/* (non-Javadoc)
		 * @see org.flexdock.perspective.PerspectiveFactory#getPerspective(java.lang.String)
		 */
		public Perspective getPerspective(String persistentId) {
			if(DEFAULT_PERSPECTIVE.equals(persistentId)) {
				return createDefaultPerspective();
			}
			return null;
		}

		/**
		 * Creates a new BrowserPerspective object.
		 *
		 * @return the perspective
		 */
		private Perspective createDefaultPerspective() {
			Perspective perspective = new Perspective(DEFAULT_PERSPECTIVE, "Default");
			LayoutSequence sequence = perspective.getInitialSequence(true);

			sequence.add(DOCKING_LIST_VIEW);
			sequence.add(DOCKING_TREE_VIEW, DOCKING_LIST_VIEW, DockingConstants.WEST_REGION, .3f);

			sequence.add(DOCKING_BOOKMARK_VIEW, DOCKING_TREE_VIEW);
			sequence.add(DOCKING_HISTORY_VIEW, DOCKING_TREE_VIEW);

			sequence.add(DOCKING_SEARCH_VIEW, DOCKING_LIST_VIEW);

			return perspective;
		}

	}

	/**
	 * A factory for creating View objects.
	 */
	public class ViewFactory extends DockableFactory.Stub {

		/** The title. */
		public String title = "Unknown";

		/* (non-Javadoc)
		 * @see org.flexdock.docking.DockableFactory.Stub#getDockableComponent(java.lang.String)
		 */
		@Override
		public Component getDockableComponent(String dockableId) {

			if (DOCKING_LIST_VIEW.equals(dockableId)) {
				JToolBar bar = new JToolBar("TestToolBar");

				bar.add(createToolBarButton(actionMap.get(CREATEFOLDER_ACTION_COMMAND)));
				bar.addSeparator();
				buttonCopy= createToolBarButton(actionMap.get(COPY_ACTION_COMMAND));
				buttonCopy.setEnabled(false);
				bar.add(buttonCopy);
				buttonCut= createToolBarButton(actionMap.get(CUT_ACTION_COMMAND));
				buttonCut.setEnabled(false);
				bar.add(buttonCut);
				buttonPaste= createToolBarButton(actionMap.get(PASTE_ACTION_COMMAND));
				if((cut==true) || (copy==true))
					buttonPaste.setEnabled(true);
				else buttonPaste.setEnabled(false);
				bar.add(buttonPaste);
				buttonDownload=createToolBarButton(actionMap.get(DOWNLOAD_ACTION_COMMAND));
				buttonDownload.setEnabled(false);
				bar.add(buttonDownload);
				bar.add(createToolBarButton(actionMap.get(UPLOAD_ACTION_COMMAND)));
				bar.addSeparator();
				bar.add(createToolBarButton(actionMap.get(DETAIL_VIEW_ACTION_COMMAND)));
				bar.add(createToolBarButton(actionMap.get(LIST_VIEW_ACTION_COMMAND)));
				bar.add(createToolBarButton(actionMap.get(ICON_VIEW_ACTION_COMMAND)));
				bar.add(createToolBarButton(actionMap.get(THUMBNAIL_VIEW_ACTION_COMMAND)));
				bar.addSeparator();

				View view =createViewComponent(DOCKING_LIST_VIEW,bundle.getString("folders_and_files_docking"),shellListView,bar);
				mapViewPlugins.put(dockableId,view);
				return view;
			} else if (DOCKING_TREE_VIEW.equals(dockableId)) {
				View view = createViewComponent(DOCKING_TREE_VIEW,bundle.getString("folders_docking"),new JScrollPane(shellTreeView),null);
				view.addAction(DockingConstants.PIN_ACTION);
				mapViewPlugins.put(dockableId,view);
				return view;
			} else if (DOCKING_BOOKMARK_VIEW.equals(dockableId)) {
				BookmarkView bookmarkView = BookmarkView.getInstance();
				bookmarkView.init();
				View view = createViewComponent(DOCKING_BOOKMARK_VIEW,bundle.getString("bookmark_docking"),new JScrollPane(bookmarkView),null);
				view.addAction(DockingConstants.PIN_ACTION);
				return view;
			} else if (DOCKING_HISTORY_VIEW.equals(dockableId)) {
				HistoryView historyView = HistoryView.getInstance();
				historyView.init();
				View view = createViewComponent(DOCKING_HISTORY_VIEW,bundle.getString("history_docking"),new JScrollPane(historyView),null);
				view.addAction(DockingConstants.PIN_ACTION);
				return view;
			} else if (DOCKING_SEARCH_VIEW.equals(dockableId)) {
				searchWindow = new SearchWindow(shellTreeView.getCmisObjectTreeModel(),BrowserWindow.this);
				View view = createViewComponent(DOCKING_SEARCH_VIEW,bundle.getString("search_docking"),new JScrollPane(searchWindow),null);
				view.addAction(DockingConstants.PIN_ACTION);
				return view;
			} else if (DOCKING_PREVIEW_VIEW.equals(dockableId)) {
			} else if (DOCKING_PLUGIN_VIEW.equals(dockableId)) {
				View viewPlugin = createViewComponent(dockableId,"Unknown",new JScrollPane(),null);
				viewPlugin.addAction(DockingConstants.PIN_ACTION);
				viewPlugin.addAction(DockingConstants.CLOSE_ACTION);
				return null;
			}else if(dockableId.contains("_ged")) {
				View viewPlugin = createViewComponent(dockableId,title,new JScrollPane(),null);
				viewPlugin.addAction(DockingConstants.PIN_ACTION);
				mapViewPlugins.put(dockableId,viewPlugin);
				return viewPlugin;
			}
			return null;
		}

		/**
		 * Creates a new View object.
		 *
		 * @param id the id
		 * @param text the text
		 * @param comp the comp
		 * @param bar the bar
		 * @return the view
		 */
		private View createViewComponent(String id, String text, JComponent comp, JToolBar bar) {
			View view = new View(id, text);

			JPanel p = new JPanel();
			p.setBorder(new LineBorder(Color.GRAY, 1));
			p.setLayout(new BorderLayout());
			p.add(comp, BorderLayout.CENTER);

			if(bar!=null)
				p.add(bar,BorderLayout.NORTH);

			view.setContentPane(p);
			return view;
		}       
	}

	//hide some files
	/**
	 * Load blacklist.
	 */
	public static void loadBlacklist() {
		blacklist = new ArrayList<String>();
		try {
			URL blacklistURL = Application.class.getResource("/kiyut/ekspos/blacklist.conf");
			BufferedReader br=new BufferedReader(new InputStreamReader(blacklistURL.openStream()));
			String line;
			while ((line=br.readLine())!=null){
				blacklist.add(line);

			}
			br.close(); 
		}		
		catch (Exception e) {
			ExceptionUtils.createJXErrorException(e, null);
		}

	}



	/**
	 * Creates the new space.
	 */
	private void getNameNewFolder() {

		final StringBuilder nameNewSpace =new StringBuilder();
		final JFrame mainFrame = new JFrame(bundle.getString("CreateFolder.title"));
		//mainFrame.setIconImage(Toolkit.getDefaultToolkit().createImage(Application.class.getResource("/kiyut/ekspos/favorites.png")));
		mainFrame.setContentPane(new JPanel(new GridLayout()));
		mainFrame.setLocationRelativeTo(getParent());
		mainFrame.setIconImage(Toolkit.getDefaultToolkit().createImage(Application.class.getResource("/kiyut/ekspos/add-folder.png")));
		JPanel jPanel = new JPanel(new GridBagLayout());
		GridBagConstraints gbc = new GridBagConstraints();
		Insets insets = new Insets(2, 2, 2, 10);
		gbc.insets=insets;
		jPanel.add(new JLabel(bundle.getString("CreateFolder.type")),gbc);
		final JTextField field = new JTextField(25);
		jPanel.add(field,gbc);
		JButton button = new JButton(bundle.getString("CreateFolder.text"));
		jPanel.add(button,gbc);
		//mainFrame.setLocationRelativeTo(this);
		mainFrame.getContentPane().add(jPanel);
		mainFrame.pack();
		mainFrame.setVisible(true);
		button.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) {
				nameNewSpace.append(field.getText());
				createNewFolder(nameNewSpace.toString());
				mainFrame.dispose();
			}
		});

	}
	
	void createNewFolder(String nameNewSpace) {
		
		if(nameNewSpace.equals("")) {
			return;
		}
		final Folder target = (Folder)  shellListView.getCurrentDirectory();
		Map<String, Object> properties = new HashMap<String, Object>();
		properties.put(PropertyIds.NAME, nameNewSpace);
		properties.put(PropertyIds.OBJECT_TYPE_ID, "cmis:folder");
		
		try {
			Folder folder = (Folder) SessionHandler.getClientSession().getSession().getObjectByPath(target.getPath());
			SessionHandler.getClientSession().getSession().createFolder(properties, folder);
		} catch (CmisBaseException e) {
			ExceptionUtils.createCmisJXBaseException(e, this);
			return;
		} catch (Exception e) {
			ExceptionUtils.createJXErrorException(e, this);
			return;
		}
		shellListView.refresh();
		shellTreeView.refresh();
	}

	/**
	 * 
	 * Selected file with the right click
	 */
	public void clickedRightSelectedFile(MouseEvent evt){
		int modifiers = evt.getModifiers();
		if ((modifiers & InputEvent.BUTTON3_MASK) == InputEvent.BUTTON3_MASK) {
			int row = evt.getY() / shellListView.getDetailView().getRowHeight();
			shellListView.getDetailView().setRowSelectionInterval(row, row);
			shellListViewPopupTrigger(evt);
		}	
	}

	/**
	 * Gets the tool bar.
	 *
	 * @return the tool bar
	 */
	public JToolBar getToolBar() {
		return toolBar;
	}

	/**
	 * Gets the shell list view popup menu.
	 *
	 * @return the shell list view popup menu
	 */
	public JPopupMenu getShellListViewPopupMenu() {
		return shellListViewPopupMenu;
	}

	/**
	 * Gets the shell list view popup menu folder.
	 *
	 * @return the shell list view popup menu folder
	 */
	public JPopupMenu getShellListViewPopupMenuFolder() {
		return shellListViewPopupMenuFolder;
	} 

	/**
	 * Gets the shell list view.
	 *
	 * @return the shell list view
	 */
	public CmisObjectListView getShellListView() {
		return shellListView;
	}

	/**
	 * Gets the blacklist.
	 *
	 * @return the blacklist
	 */
	public static List<String> getBlacklist() {
		return blacklist;
	}

	/**
	 * Gets the shell tree view.
	 *
	 * @return the shell tree view
	 */
	public CmisObjectTreeView getShellTreeView(){
		return shellTreeView;
	}
	
	public void focusOnFilesTab() {
		View v3 = mapViewPlugins.get(BrowserWindow.DOCKING_LIST_VIEW);
		if(v3 != null) {
			if(v3.getParent() instanceof JTabbedPane){
				JTabbedPane tabbedPane = (JTabbedPane)v3.getParent();
				tabbedPane.setSelectedIndex(0);
				tabbedPane.setTabPlacement(JTabbedPane.TOP);
			}
		}
	}

}